package com.mini.controller;

import com.mini.service.IWebSocketService;
import com.mini.domain.model.SendBody;
import com.mini.util.AjaxJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发送消息
 */
@RestController
@RequestMapping("/send")
@Slf4j
public class SendController {

    @Autowired
    private IWebSocketService webSocketService;

    // 发送一条消息
    @PostMapping("/sendToChannels")
    public AjaxJson send(@Validated @RequestBody SendBody sendBody) {

        webSocketService.sendMessage(sendBody.getChannels(),sendBody.getContent());

        return AjaxJson.getSuccess();
    }
}
